// import { checkUserToken } from '@/api/client/user'
import { checkAdminToken } from '@/api/admin/admin'
import { checkUserToken } from '@/api/user/user'
import router from '@/router'

// 当前判断是纯前端判断，后端判断在request.js中
export const isValidToken = async () => {
  const path = router.currentRoute.path
  if (path.includes('/admin')) {
    const token = localStorage.getItem('a_t')
    if (!token) {
      return false
    }
    const res = await checkAdminToken(token)
    if (res.code === 401) {
      localStorage.removeItem('a_t')
      localStorage.removeItem('a_u')
      return false
    }
  } else {
    const token = localStorage.getItem('u_t')
    if (!token) {
      return false
    }
    const res = await checkUserToken(token)
    if (res.code === 401) {
      localStorage.removeItem('u_t')
      localStorage.removeItem('u_u')
      return false
    }
  }
  return true
}
